package com.example.replacebooks.controller;

import com.example.replacebooks.common.Result;
import com.example.replacebooks.entity.Class;
import com.example.replacebooks.entity.Params;
import com.example.replacebooks.service.ClassService;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("/class")
public class ClassController {

    private static final Logger log = LoggerFactory.getLogger(ClassController.class);

    @Resource
    private ClassService classService;

    @GetMapping
    public Result findAll(){return Result.success(classService.findAll());}

    @GetMapping("/search")
    public Result findBySearch(Params params){
        PageInfo<Class> info = classService.findBySearch(params);
        return Result.success(info);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Class clas){
        classService.add(clas);
        return Result.success();
    }

    @DeleteMapping("/{classid}")
    public Result delete(@PathVariable Integer classid){
        classService.delete(classid);
        return Result.success();
    }
}
